package com.lighting.common.dubbo.filter;

import com.lighting.common.core.util.JsonUtil;
import com.lighting.common.log.TraceBuilder;
import com.lighting.common.log.TraceConstant;
import com.lighting.common.log.TraceUtils;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate(group = CommonConstants.PROVIDER)
public class ProviderFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        TraceUtils.withBuilderInTrace(JsonUtil.parseObject(invocation.getAttachment(TraceConstant.TRACE_INFO), TraceBuilder.class));

        return invoker.invoke(invocation);
    }
}